%table{ class: 'records search_combinations' }
  %thead
    %tr
      %th.combined_search_operator
      %th.combined_search
        Searches
      %th.remove
      %th
  %tbody.nested_records_search_combinations
    - if combined_searches_options(@discerner_search).blank?
      %td{colspan: '4'}
        No qualifying searches found
    - else
      - @discernerSearchCombinationsTemplate = discerner_generate_nested_attributes_template(f, :search_combinations, 'search_combination')
      = f.fields_for :search_combinations, f.object.search_combinations.ordered_by_display_order do |search_combination|
        = render partial: 'search_combination_fields', locals: { f: search_combination }

      %tfoot
        %tr
          %td{ colspan: '4', class: 'add_search_combinations_link' }
            = discerner_link_to_add_fields "Add search", :search_combinations
.clear

:javascript
  $(function () {
    var discernerSearchCombinationsTemplate = '#{@discernerSearchCombinationsTemplate}';
    if (discernerSearchCombinationsTemplate) {
      new Discerner.SearchCombination.UI({
        searchCombinationsTemplate: discernerSearchCombinationsTemplate
      })
    }
  });
